package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.service.IEmployeeService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 登录登出  已经交给shiro处理了 不需要登录控制器
 */
/*@Controller
public class LoginController {


    @Autowired
    private IEmployeeService employeeServiceImpl;

    @ResponseBody
    @RequestMapping("/login")
    public JsonResult login(String username, String password, HttpSession session) {
        try {
            Employee employee = employeeServiceImpl.login(username, password);
            //从数据库中查询出用户 若存在 往session中存进
            session.setAttribute(UserContext.EMPLOYEE_IN_SESSION, employee);
            //判断 如果当前用户不是超管 才查询(因为超管拦截器会直接放行)
            if(!employee.isAdmin()){
                //登录时 查询出该员工的权限表达式集合 并存进Session中
                List<String> expressions = employeeServiceImpl.getPermissionByEmployeeId(employee.getId());
                session.setAttribute(UserContext.EXPRESSIONS_IN_SESSION, expressions);
            }
            return new JsonResult("登录成功", true);
        } catch (Exception e) {
            e.printStackTrace();
            //若没有查询 抛异常 提示错误
            return new JsonResult("用户或密码错误", false);
        }
    }
}*/
